package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ChildAnalysis
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPerAnalysisInfor

object AnalysisInforIndexHelp {

    fun getChildListBean(
            paperPerAnalysisInfor: PaperPerAnalysisInfor,
            index_A: Int,
            index_B: Int,
            index_C: Int
    ): ChildAnalysis {
        return paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList[index_C]
    }

    /*
    * 获取试题位置index
    * */
    fun SortIndex_return_ParentVpPosition(paperPerAnalysisInfor: PaperPerAnalysisInfor,sortIndex:String):Int{
        var parentPosition = -1
        var TypeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@for(a in 0 until TypeListSize){
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesList.size
            for(b in 0 until QuesListSize){
                parentPosition += 1
                var SortIndexListSize = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList.size
                for(c in 0 until SortIndexListSize){
                    var SortIndex = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList[c].SortIndex
                    if(SortIndex == sortIndex){
                        break@outLoop
                    }
                }
            }
        }
        return parentPosition
    }

    fun SortIndex_return_IndexA(paperPerAnalysisInfor: PaperPerAnalysisInfor,sortIndex:String):Int{
        var index_A = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@for(a in 0 until typeListSize){
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesList.size
            for(b in 0 until QuesListSize){
                var SortIndexListSize = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList.size
                for(c in 0 until SortIndexListSize) {
                    var SortIndex = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList[c].SortIndex
                    if (SortIndex == sortIndex) {
                        index_A = a
                        break@outLoop
                    }
                }
            }
        }
        return index_A
    }

    fun SortIndex_return_IndexB(paperPerAnalysisInfor: PaperPerAnalysisInfor,sortIndex:String):Int{
        var index_B = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@for(a in 0 until typeListSize){
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesList.size
            for(b in 0 until QuesListSize){
                var SortIndexListSize = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList.size
                for(c in 0 until SortIndexListSize) {
                    var SortIndex = paperPerAnalysisInfor.TypeList[a].QuesList[b].SortIndexList[c].SortIndex
                    if (SortIndex == sortIndex) {
                        index_B = b
                        break@outLoop
                    }
                }
            }
        }
        return index_B
    }

    //目前匹配题专用
    fun ItemSortIndex_return_IndexC(paperPerAnalysisInfor: PaperPerAnalysisInfor, itemSortIndex: String): Int {
        var index_C = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList.size
            for (b in 0 until QuesListSize) {
                var childListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndexA = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndexA.contains(itemSortIndex)) {
                            index_C = c
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_C
    }

    //目前匹配题专用
    fun ItemSortIndex_return_IndexD(paperPerAnalysisInfor: PaperPerAnalysisInfor, itemSortIndex: String): Int {
        var index_D = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList.size
            for (b in 0 until QuesListSize) {
                var childListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndexA = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndexA.contains(itemSortIndex)) {
                            index_D = d
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_D
    }


    /*
   * 获取题型序号从0开始
   * */
    fun ParentVpIndex_return_TypeListPosition(paperPerAnalysisInfor: PaperPerAnalysisInfor, position: Int): Int {
        var positionX = -1
        var typeListPosition = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesList.size
            for (b in 0 until QuesListSize) {
                positionX += 1
                if (position == positionX) {
                    typeListPosition = a
                    break@outLoop
                }
            }
        }
        return typeListPosition
    }

    fun ParentVpIndex_return_QuesListPosition (paperPerAnalysisInfor: PaperPerAnalysisInfor,position: Int): Int {
        var positionX = -1
        var quesListPosition = 0
        var typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPerAnalysisInfor.TypeList[a].QuesList.size
            for (b in 0 until QuesListSize) {
                positionX += 1
                if (position == positionX) {
                    quesListPosition = b
                    break@outLoop
                }
            }
        }
        return quesListPosition
    }


    fun ItemSortIndex_return_ChildVpIndex(paperPerAnalysisInfor: PaperPerAnalysisInfor,itemsortIndex: String): Int {
        var childVpIndex = -1
        val typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesDetailListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList.size
            for (b in 0 until quesDetailListSize) {
                childVpIndex = -1
                var childListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    var itemListSize = getChildListBean(paperPerAnalysisInfor, a, b, c).ItemList.size
                    for (d in 0 until itemListSize) {
                        childVpIndex += 1
                        val itemSortIndexA = getChildListBean(paperPerAnalysisInfor, a, b, c).ItemList[d].ItemSortIndex
                        if (itemSortIndexA.contains(itemsortIndex)) {
                            break@outLoop
                        }
                    }
                }
            }
        }
        return childVpIndex
    }

    fun ItemSortIndex_return_ScorllPosition(paperPerAnalysisInfor: PaperPerAnalysisInfor, itemsortIndex: String): Int {
        var scorllPosition = -1
        val typeListSize = paperPerAnalysisInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesDetailListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList.size
            for (b in 0 until quesDetailListSize) {
                scorllPosition = -1
                var childListSize = paperPerAnalysisInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    var itemListSize = getChildListBean(paperPerAnalysisInfor, a, b, c).ItemList.size
                    for (d in 0 until itemListSize) {
                        scorllPosition += 1
                        val itemSortIndexA = getChildListBean(paperPerAnalysisInfor, a, b, c).ItemList[d].ItemSortIndex
                        if (itemSortIndexA.contains(itemsortIndex)) {
                            break@outLoop
                        }
                    }
                }
            }
        }
        return scorllPosition
    }

    //通过小题序号 -> ItemSortIndex
    fun ChildVpIndex_return_ItemSortIndex(paperPerAnalysisInfor: PaperPerAnalysisInfor, index_A: Int, index_B: Int, childVpIndex: Int): String {
        var itemSortIndex = ""
        var childVpIndexA = -1
        var childListSize = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
        outLoop@ for (c in 0 until childListSize) {
            var itemListSize = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList.size
            for (d in 0 until itemListSize) {
                childVpIndexA += 1
                if (childVpIndexA == childVpIndex) {
                    val AAA = index_A
                    val BBB = index_B
                    val CCC = c
                    val DDD = d
                    itemSortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[d].ItemSortIndex
                    break@outLoop
                }
            }
        }
        return itemSortIndex
    }



}